<?php
require_once "config.php";
$offer_obj = new Offer();
$active_offers = $offer_obj->list_active_offers();
$rotator_ids=array();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hotels With Offers</title>
<script language="Javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="Javascript" type="text/javascript" src="js/jquery.countdown.js"></script>
<link href="css/jquery.countdown.css" rel="stylesheet" type="text/css" />
<link href="css/main.css" rel="stylesheet" type="text/css" />
<?php require_once 'rotator_utils.php'; ?>
</head>
 <script language="javascript" type="text/javascript">
         $(function(){
          <?php $k = 1;
        foreach ($active_offers as $active_offer) {
               $offer_hour = substr($active_offer['offer_end_date'], 11, 2) ;
               $offer_min =  substr($active_offer['offer_end_date'], 14, 2);
               $offer_sec =  substr($active_offer['offer_end_date'], 17, 2);
               $offer_day =  substr($active_offer['offer_end_date'], 8, 2);
               $offer_month = substr($active_offer['offer_end_date'], 5, 2);
               $offer_year =  substr($active_offer['offer_end_date'], 0, 4);
               ?>
        var austDay = new Date(<?=$offer_year?>,<?=($offer_month-1)?>,<?=$offer_day?>,<?=$offer_hour?>,<?=$offer_min?>,<?=$offer_sec?>);
	$('#counter_<?=$k?>').countdown({until: austDay});

<?php
    $k++;
        }
        ?>

      });



		</script>

<body>
<div id="wrapper">
<?php require_once 'top_header.php'; ?>

<div class="contentPane">
  <div id="sidebar">
    <span class="menu"><img src="images/call.png" alt="Advertise with Hotel with Offers" class="callus"  /></span>
    <div class="joinus">
      <h1>INVITE A FRIEND</h1>
      <h2>Tell a friend and win Rs100.00</h2>
      <div class="joinbtn"><a href="#">LEARN&nbsp;MORE</a></div>
     </div>
    <div class="reserve"><span class="reserveitem">Reserved for :</span> <span class="reserveitem">advertising</span> <span class="reserveitem">latest news</span> <span class="reserveitem">soon ending deals &amp; offers</span></div>
  </div>
  <div class="leftPane">
      <div class="mainMenu"><?php require_once 'main_menu.php'; ?></div>
    <?php require_once 'newsletter_plug.php'; ?>
    <div id="Listings">
        <?php        
        if(!empty($active_offers)) {
            $j =1;
            foreach ($active_offers as $active_offer) {
               $you_saved = number_format(floor($active_offer['discount_amount']));
               $discount_percentage = ceil((( $active_offer['discount_amount'])/$active_offer['regular_amount'])*100);
               $item_sold = $offer_obj->get_noof_sold_items($active_offer['offer_id']);
               $price_class = "";
               switch (strlen(floor($active_offer['regular_amount']-$active_offer['discount_amount']))) {
                case "3":
                   $price_class ="class='digits3'";
                    break;
                 case "4":
                   $price_class ="class='digits4'";
                    break;
                case "5":
                   $price_class ="class='digits5'";
                    break;
                 case "6":
                   $price_class ="class='digits6'";
                    break;
                 case "7":
                   $price_class ="class='digits7'";
                    break;
}
?>
      <div class="item">
        <div class="content">
          <div class="imageHolder">
              <div class="offerAlert"><?=$discount_percentage?>%<br>
              <strong>OFF</strong></div>
              <div id="rotator<?php echo $active_offer['offer_id']?>" rel="rot">
                <div class="corners"></div>
                <ul>
                    <?php 
                    $rotator_ids[$active_offer['offer_id']]='rotator'.$active_offer['offer_id'];    //used to store the offer ids, to pass to the 'theRotator' funtion
                    $offer_images=$offer_obj->get_offer_images($active_offer['offer_id']);  //loads all the offer images related to the current offer from the offer_order table.
                    if(!empty($offer_images)){
                      foreach ($offer_images as $key => $value): 
                       $class_text='';                      
                       if($key==0){ //starts the rotation from the first image
                           $class_text=' class="show"';
                       }                       
                       $path="images/".$value['image_name'];
                       if(!file_exists("images/".$value['image_name'])){
                           $path="images/sample_image.jpg";
                       }
                      ?>                    
                        <li <?php echo $class_text;?>><img src="<?php echo $path;?>" width="282" height="196" alt="Hotel with Offers" /></li>
                      <?php endforeach;?>
                    <li><img src="images/image-4.jpg" width="282" height="196" alt="Hotel with Offers" /></li>
                    <?php }else {?>
                        <li class="show"><img src="images/sample_image.jpg" width="282" height="196" alt="Hotel with Offers" /></li>                    
                        <li><img src="images/image-4.jpg" width="282" height="196" alt="Hotel with Offers" /></li>
                    <?php }?>
                </ul>                    
            </div>
          </div>
          <div class="intro">
              <div class="introUpper">
              <div class="socialNetworkWidgets">
               <script>function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}</script><style> html .fb_share_link { padding:2px 0 0 20px; height:16px; background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top left; }</style><a rel="nofollow" href="http://www.facebook.com/share.php?u=http://www.hotelswithoffers.com/<?=$active_offer['offer_prefix']?>.html" onclick="return fbs_click()" target="_blank" class="fb_share_link"></a>
               <a href="https://twitter.com/share" class="twitter-share-button" data-lang="en">Tweet</a>
               <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
               </div>
                <h1><a href="<?=$active_offer['offer_prefix']?>.html"><?=$active_offer['offer_title'];?></a></h1>

                <h2 class="description"><?=$active_offer['offer_overview']?>. ...</h2>

              </div>
              <div class="introLower">
                <div class="actions">
                  <div class="pricing">
                    <ul>
                      <li class="normalPrice"><em>Normal Price</em><br />
                        Rs.<?php echo number_format(floor($active_offer['regular_amount'])); ?></li>
                      <li><em>You Save</em><br />Rs.<?=$you_saved?></li>
                    </ul>
                  </div>
                  <div class="callToAction">
                    <div class="moreInfo"><a href="<?=$active_offer['offer_prefix']?>.html">more info</a></div>
                  	<div class="buyNow"><a href="buynow.php?offer_prefix=<?=$active_offer['offer_prefix']?>"><img src="images/button_buynow.png" alt="Hotel with Offers | Buy Now" width="108" height="37" border="0" /></a></div>
                  </div>

                </div>
                <div class="price currencyUSD">
                  <h1><a href="<?=$active_offer['offer_prefix']?>.html"><?=$discount_percentage?>% OFF</a></h1>
                  <h2><a <?php echo $price_class; ?> href="<?=$active_offer['offer_prefix']?>.html"><strong>Rs </strong><?php echo number_format(floor($active_offer['regular_amount']-$active_offer['discount_amount']));?></a></h2>
                  <h3><a href="<?=$active_offer['offer_prefix']?>.html"><?=$item_sold?> SOLD</a></h3>
                </div>
              </div>
          </div>
</div>
        <div class="footer">
            <div class="countdown">
                <div id="counter_<?=$j?>"></div>
           </div>
<!--          <div class="askQuestion"><a href="#">Ask a question about this offer</a></div>
-->        </div>
            <br class="clear">
            <br class="clear">
      </div>
      <?php
      $j++;
            }

        }
        ?>


    </div>
    <div class="clear"></div>
</div>
</div>
<div class="clear"></div>
</div>
<div id="footerWrapper">
<?php require_once 'footer.php'; ?>
</div>

</body>
</html>
<script type="text/javascript">
    $(document).ready(function() {		
	//Load the slideshow
        <?php foreach ($rotator_ids as $val) {?>
            theRotator('<?php echo $val?>');
        <?php }?>
	
	/*$('div.rotator').fadeIn(1000);
        $('div.rotator ul li').fadeIn(1000); // tweek for IE*/
    });
</script>